package com.ec.core.dao;

/**
 * <p>Title: ec</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2008 7</p>
 *
 * <p>Company: ec</p>
 *
 * @author pgf
 * @version 1.0
 */
import java.util.Hashtable;
import java.util.ArrayList;
import java.util.Iterator;

public class DataTableMeta {
    private String tableName;
    private String pkName;
    private Hashtable<String,DataFieldMeta> fields  = new Hashtable<String,DataFieldMeta>();

    public DataTableMeta() {
    }

	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getPkName() {
		return pkName;
	}

	public void setPkName(String pkName) {
		this.pkName = pkName;
	}

	public Hashtable<String,DataFieldMeta> getFields() {
		return fields;
	}

	public void setFields(Hashtable<String,DataFieldMeta> fields) {
		this.fields = fields;
	}
	
	public ArrayList<DataFieldMeta> getAvailableFields(){
		Iterator<String> ii = fields.keySet().iterator();
		ArrayList<DataFieldMeta> availFields = new ArrayList<DataFieldMeta>();
		while(ii.hasNext()){
			DataFieldMeta dfm = fields.get(ii.next());
			if(!dfm.isReadonly()){
				availFields.add(dfm);
			}
		}
		return availFields;
	}
	public ArrayList<DataFieldMeta> getUpdateFields(){
		Iterator<String> ii = fields.keySet().iterator();
		ArrayList<DataFieldMeta> updateFields = new ArrayList<DataFieldMeta>();
		while(ii.hasNext()){
			DataFieldMeta dfm = fields.get(ii.next());
			if(dfm.isReadonly()==false && dfm.isPk()==false){
				updateFields.add(dfm);
			}
		}
		return updateFields;
	}
	
	public DataFieldMeta getField(String fieldName){
		Iterator<String> ii = fields.keySet().iterator();
		while(ii.hasNext()){
			DataFieldMeta dfm = fields.get(ii.next());
			if(dfm.getFieldName().equals(fieldName.toUpperCase())){
				return dfm;
			}
		}
		return null;
	}
	
	public DataFieldMeta getPkField(){
		Iterator<String> ii = fields.keySet().iterator();
		while(ii.hasNext()){
			DataFieldMeta dfm = fields.get(ii.next());
			if(dfm.isPk()){
				return dfm;
			}
		}
		return null;
	}
	
}
